package vip.xiaonuo.vein.service.sn;

import org.springframework.stereotype.Service;

@Service
public class ListSnGenerate implements SnNoGenerateStrategy{

    private ListSnGenerate(){}

    private final static ListSnGenerate generate = new ListSnGenerate();

    public static ListSnGenerate getInstance(){
        return generate;
    }

    private static int[] indexArr = new int[CODE_LENGTH];
    static {
        for(int i = 0 ; i < CODE_LENGTH ; i ++){
            indexArr[i] = 0;
        }
    }

    @Override
    public synchronized String getSnNo(String deviceID){
        StringBuilder sb = new StringBuilder();
        for(int i = 0  ; i < indexArr.length   ; i++){
            sb.append(str.charAt(indexArr[i]));
        }

        for(int i = indexArr.length-1  ; i >= 0 ; i--){
            indexArr[i] = indexArr[i] +1;
            if(indexArr[i] > str.length()-1){
                indexArr[i] = 0;
            }else{
                break;
            }
        }
        return sb.toString();
    }


}
